package classTest_03.factory;

import classTest_03.dao.NewsDao;
import classTest_03.dao.impl.NewsDaoImpl;
import classTest_03.dao.impl.NewsDaoMySqlImpl;
import classTest_03.dao.impl.NewsDaoOracleImpl;
import classTest_03.dao.impl.NewsDaoRedisImpl;

/**
 * 示例1：创建NewsDao实例的工厂类
 */
public class SimpleDaoFactory {
    /**
     * 创建NewsDao实例的工厂方法
     */
    public static NewsDao getInstance(){
        return new NewsDaoImpl();
    }


    //示例4
    /**
     * 创建NewsDao实例的工厂方法
     */
    public static NewsDao getInstance(String key){
        switch (key){
            case  "mysql":
                return new NewsDaoMySqlImpl();
            case "oracle":
                return new NewsDaoOracleImpl();
            case "redis":
                return new NewsDaoRedisImpl();
            default:
                throw new RuntimeException("无效的数据库类型："+key+",DAO获取失败");
        }
    }
}
